package com.example.campusproject.slice;

import com.example.campusproject.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;

public class XYFJAbilitySlice extends AbilitySlice {
    private int[] images={
            ResourceTable.Media_baosige,ResourceTable.Media_xike1,
            ResourceTable.Media_xike2,ResourceTable.Media_xike3,
            ResourceTable.Media_xike4,ResourceTable.Media_xike5,
            ResourceTable.Media_xike6,ResourceTable.Media_xike7,
            ResourceTable.Media_xike8,ResourceTable.Media_xike9,
            ResourceTable.Media_xike10,ResourceTable.Media_xike11,
            ResourceTable.Media_xike13,ResourceTable.Media_xike12,
            ResourceTable.Media_xike14,ResourceTable.Media_xike15,
            ResourceTable.Media_xike16,ResourceTable.Media_xike17,
            ResourceTable.Media_xike18,ResourceTable.Media_xike19
    };
    private Image iv_xyfj;
    private DirectionalLayout dl;
    private Image[] images_=new Image[images.length];
    private Button btn_xyfj;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        this.setUIContent(ResourceTable.Layout_ability_xyfj);
        iv_xyfj= (Image) this.findComponentById(ResourceTable.Id_iv_xyfj);
        dl= (DirectionalLayout) this.findComponentById(ResourceTable.Id_dl);
        btn_xyfj= (Button) this.findComponentById(ResourceTable.Id_btn_xyfj);
        for (int i = 0; i < images_.length; i++) {
            images_[i]=new Image(this);
            DirectionalLayout.LayoutConfig lc=new DirectionalLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_CONTENT,
                    ComponentContainer.LayoutConfig.MATCH_PARENT);
            images_[i].setLayoutConfig(lc);
            images_[i].setPixelMap(images[i]);
            images_[i].setTag(i);
            images_[i].setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    int n= (int) ((Image)component).getTag();
                    iv_xyfj.setPixelMap(images[n]);
                }
            });
            dl.addComponent(images_[i]);
        }
        images_[0].setAlpha(255);
        btn_xyfj.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                terminate();
            }
        });
    }
}
